package com.yaozheng.vocationaltraining.activity;

import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.TextView;

import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.Extra;
import org.androidannotations.annotations.ViewById;

import com.yaozheng.vocationaltraining.R;

/**
 * 新闻详情页面
 *
 * @author Administrator
 */
@EActivity(R.layout.fragment_html5)
public class NewsDetailActivity extends BaseActivity {
    @Extra
    String title;
    @Extra
    String contentUrl;
    @ViewById
    WebView html5WebView;
    @ViewById
    TextView headTitleText;


    @AfterViews
    public void initView() {
        headTitleText.setText(title);
        //启用支持javascript
        WebSettings settings = html5WebView.getSettings();
        settings.setJavaScriptEnabled(true);
        // 设置可以支持缩放
        settings.setSupportZoom(true);
// 设置出现缩放工具
        settings.setBuiltInZoomControls(true);

        //扩大比例的缩放
        settings.setUseWideViewPort(true);
//自适应屏幕
        settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
        settings.setLoadWithOverviewMode(true);

        settings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
        html5WebView.setWebViewClient(new WebViewClient() {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                return false;
            }


        });
        html5WebView.setWebChromeClient(new WebChromeClient() {
            @Override
            public void onReceivedTitle(WebView view, String title) {
                super.onReceivedTitle(view, title);
                headTitleText.setText(title);
            }

        });
        html5WebView.loadUrl(contentUrl);
    }

    @Override
    public void backClick() {
        if (html5WebView.canGoBack()) {
            html5WebView.goBack();
        } else {
            super.backClick();
        }
    }

}
